package org.ruoyi.graph2.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.ruoyi.graph2.domain.bo.GraphBaseBo;
import org.ruoyi.graph2.domain.vo.GraphBaseVo;
import org.ruoyi.graph2.service.IGraphBaseService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.ruoyi.common.idempotent.annotation.RepeatSubmit;
import org.ruoyi.common.log.annotation.Log;
import org.ruoyi.common.web.core.BaseController;
import org.ruoyi.core.page.PageQuery;
import org.ruoyi.common.core.domain.R;
import org.ruoyi.common.core.validate.AddGroup;
import org.ruoyi.common.core.validate.EditGroup;
import org.ruoyi.common.log.enums.BusinessType;
import org.ruoyi.common.excel.utils.ExcelUtil;
import org.ruoyi.core.page.TableDataInfo;

/**
 * 图谱基础信息表
 *
 * @author ageerle
 * @date Tue Nov 18 15:28:04 CST 2025
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/graphBase")
public class GraphBaseController extends BaseController {

    private final IGraphBaseService graphBaseService;

	/**
	 * 查询图谱基础信息表列表
	 */
	@SaCheckPermission("dev:graphBase:list")
	@GetMapping("/list")
    public TableDataInfo<GraphBaseVo> list(GraphBaseBo bo, PageQuery pageQuery) {
        return graphBaseService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出图谱基础信息表列表
     */
    @SaCheckPermission("dev:graphBase:export")
    @Log(title = "图谱基础信息表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(GraphBaseBo bo, HttpServletResponse response) {
        List<GraphBaseVo> list = graphBaseService.queryList(bo);
        ExcelUtil.exportExcel(list, "图谱基础信息表", GraphBaseVo.class, response);
    }

    /**
     * 获取图谱基础信息表详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("dev:graphBase:query")
    @GetMapping("/{id}")
    public R<GraphBaseVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(graphBaseService.queryById(id));
    }

    /**
     * 新增图谱基础信息表
     */
    @SaCheckPermission("dev:graphBase:add")
    @Log(title = "图谱基础信息表", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody GraphBaseBo bo) {
        return toAjax(graphBaseService.insertByBo(bo));
    }

    /**
     * 修改图谱基础信息表
     */
    @SaCheckPermission("dev:graphBase:edit")
    @Log(title = "图谱基础信息表", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody GraphBaseBo bo) {
        return toAjax(graphBaseService.updateByBo(bo));
    }

    /**
     * 删除图谱基础信息表
     *
     * @param ids 主键串
     */
    @SaCheckPermission("dev:graphBase:remove")
    @Log(title = "图谱基础信息表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(graphBaseService.deleteWithValidByIds(List.of(ids), true));
    }
}
